import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15
import QtLocation 5.15
import QtPositioning 5.15
ApplicationWindow {
    id: window
    visible: true
    width: 1024
    height:768
    title: "探测推演"
    property var items:[]
    property var selected:0
    property var curStep: 0
    property var maxStep: 0
    property var visibleDetail: true
    property var visibleDetects: true
    property var visibleRouteline: true
    property var visibleSignaturegon: true
    property var visibleRange: true
    property var isStrategyAvailable: true
    property var isDSAvailable: true
    property var standardSignature: 1
    property var timeInverval: 60
    property var standardRange: 100*1000
    property var typename: {'target':'目标','sensor':'探测器'}
    property var typecolor: {'target':'red','sensor':'blue'}
    property var operationState: 0
    function updateMaxStep(){
        maxStep=0
        items.forEach(function(item){
            maxStep=Math.max(maxStep,item.routed.length)
        })
    }
    function updateCoordinate(){
        items.forEach(function(item){
            item.setCurrent(curStep)
        })
    }
    function updateDetects(){
        items.forEach(function(item){
            item.jiansuo=false
            item.shijia=false
            item.zhebi=false
            item.ganrao=false
        })
        for(var i=0;i<items.length;i++){
            items[i].updateDetects()
        }
    }
    function clearDetects(){
        for(var i=0;i<items.length;i++){
            for(var j=0;j<items.length;j++){
                map.removeMapItemGroup(items[i].detects[j])
            }
            items[i].detects.length=0
        }
    }
    function createDetects(){
        for(var i=0;i<items.length;i++){
            for(var j=0;j<items.length;j++){
                items[i].detects.push(d.createObject(map))
                items[i].detects[items[i].detects.length-1].fromIndex=i
                items[i].detects[items[i].detects.length-1].toIndex=j
                map.addMapItemGroup(items[i].detects[items[i].detects.length-1])
            }
        }
        updateDetects()
    }
//    onSelectedChanged: {
//        comboBoxTarget.currentIndex=comboBoxTarget.find(items[selected].name)
//    }
    menuBar: MenuBar{
        Menu{
            title: '显示'
            MenuItem{
                text: '推演界面'
                onClicked: {
                    sv.currentIndex=0
                }
            }
            MenuItem{
                text: '环境设置'
                onClicked: {
                    sv.currentIndex=1
                }
            }
        }
    }
    SwipeView{
        id:sv
        anchors.fill: parent
        interactive: false
        Component.onCompleted: {
            contentItem.highlightMoveDuration=0
        }
        Page{
            header:ToolBar{
                Column{
                    Row{
                        ToolButton{
                            text: '删除'
                            onClicked: {
                                clearDetects()
                                map.removeMapItemGroup(items[selected])
                                items.splice(selected,1)
                                items.forEach(function(item,index){
                                    item.index=index
                                })
                                if(selected>=items.length-1){
                                    selected=items.length-1
                                }
                                createDetects()
                                updateDetects()
                            }
                        }
                        ToolButton{
                            text: '开始'
                            onClicked: {
                                timer.running=true
                                items.forEach(function(item){
                                    item.routeline.toroute()
                                })
                                updateMaxStep()
                            }
                        }
                        ToolButton{
                            text: '暂停'
                            onClicked: {
                                timer.running=false
                            }
                        }
                        ToolButton{
                            text: '复位'
                            onClicked: {
                                timer.running=false
                                curStep=0
                                updateCoordinate()
                                updateDetects()
                            }
                        }
                        ToolButton{
                            text: '清除特征信号'
                            onClicked: {
                                items[selected].signaturegon.path=[]
                                items[selected].signatured=[]
                            }
                        }
                        ToolButton{
                            text: '清除航迹'
                            onClicked: {
                                items[selected].routeline.path=[]
                            }
                        }
                        ToolButton{
                            text: '生成特征信号'
                            onClicked: {
                                items[selected].signaturegon.tosignature()
                                updateDetects()
                            }
                        }
                        ToolButton{
                            text: '生成航迹'
                            onClicked: {
                            }
                        }
                        Label{
                            text: '目标'
                        }
                        ComboBox {
                            id: comboBoxTarget
                            textRole: 'name'
                            model:ListModel {
                                ListElement {name:'战斗机';altitude:10000;ref:1;range:100000;image:'file:u/战斗机';signatureRatio:.5}
                                ListElement {name:'轰炸机';altitude:15000;ref:1;range:300000;image:'file:u/轰炸机';signatureRatio:2}
                                ListElement {name:'地面车辆';altitude:0;ref:1;range:50000;image:'file:u/地面车辆';signatureRatio:1}
                                ListElement {name:'巡洋舰';altitude:0;ref:1;range:50000;image:'file:u/巡洋舰';signatureRatio:1.5}
                                ListElement {name:'航空母舰';altitude:0;ref:1;range:50000;image:'file:u/航空母舰';signatureRatio:2}
                                ListElement {name:'卫星';altitude:10000000;ref:1;range:50000;image:'file:u/卫星';signatureRatio:3}
                            }
                        }
                        Label{
                            text: '探测器'
                        }
                        ComboBox {
                            id: comboBoxSensor
                            textRole: 'name'
                            model:ListModel {
                                ListElement {name:'预警机';altitude:10000;ref:1;range:400000;image:'file:u/预警机';signatureRatio:1}
                                ListElement {name:'长曲棍球';altitude:100000000;ref:1;range:800000;image:'file:u/长曲棍球';signatureRatio:1}
                                ListElement {name:'海基X波段雷达';altitude:0;ref:1;range:1000000;image:'file:u/海基X波段雷达';signatureRatio:1}
                                ListElement {name:'宙斯盾';altitude:0;ref:1;range:300000;image:'file:u/宙斯盾';signatureRatio:1}
                                ListElement {name:'声呐';altitude:-400;ref:1;range:500000;image:'file:u/声呐';signatureRatio:1}
                                ListElement {name:'红外探测器';altitude:10000;ref:1;range:100000;image:'file:u/红外探测器';signatureRatio:1}
                            }
                        }
                        ToolButton{
                            text: '重置地图视图'
                            onClicked: {
                                map.bearing=0
                                map.tilt=0
                            }
                        }
                    }
                    Row{
                        CheckBox{
                            text: '显示详细信息'
                            checked: true
                            onCheckedChanged: {
                                visibleDetail=checked
                            }
                        }
                        CheckBox{
                            text: '显示探测信息'
                            checked: true
                            onCheckedChanged: {
                                visibleDetects=checked
                            }
                        }
                        CheckBox{
                            text: '显示航迹'
                            checked: true
                            onCheckedChanged: {
                                visibleRouteline=checked
                            }
                        }
                        CheckBox{
                            text: '显示探测范围'
                            checked: true
                            onCheckedChanged: {
                                visibleRange=checked
                            }
                        }
                        CheckBox{
                            text: '显示特征信号'
                            checked: true
                            onCheckedChanged: {
                                visibleSignaturegon=checked
                            }
                        }
                        CheckBox{
                            text: '采用DS证据理论'
                            checked: true
                            onCheckedChanged: {
                                isDSAvailable=checked
                                updateDetects()
                            }
                        }
                        CheckBox{
                            text: '采用策略'
                            checked: true
                            onCheckedChanged: {
                                isStrategyAvailable=checked
                                updateDetects()
                            }
                        }
                        Label{
                            text: '仿真步长(s)'
                        }
                        TextField{
                            text:timeInverval.toPrecision(6)
                            selectByMouse: true
                            onEditingFinished: {
                                timeInverval=parseFloat(text)
                            }
                        }
                    }
                    Row{
                        RadioButton {
                            checked: true
                            text:"默认操作"
                            onClicked: {
                                operationState=0
                            }
                        }
                        RadioButton {
                            text:"添加目标"
                            onClicked: {
                                operationState=1
                            }
                        }
                        RadioButton {
                            text:"添加探测器"
                            onClicked: {
                                operationState=2
                            }
                        }
                        RadioButton {
                            text:"添加航迹"
                            onClicked: {
                                operationState=3
                            }
                        }
                        RadioButton {
                            text:"添加特征信号"
                            onClicked: {
                                operationState=4
                            }
                        }
                    }
                    Row{
                        CheckBox{
                            id:qixiang1
                            text: '气象'
                            onCheckedChanged: {
                                updateDetects()
                            }
                        }
                        CheckBox{
                            id:daqibodao1
                            enabled: qixiang1.checked
                            text:'大气波导'
                            onCheckedChanged: {
                                updateDetects()
                            }
                        }
                        CheckBox{
                            id:cloud1
                            enabled: qixiang1.checked
                            text:'云'
                            onCheckedChanged: {
                                updateDetects()
                            }
                        }
                        CheckBox{
                            id:rain1
                            enabled: qixiang1.checked
                            text:'雨(mm/h)'
                            onCheckedChanged: {
                                updateDetects()
                            }
                        }
                        TextField{
                            id:rainVolume1
                            enabled: qixiang1.checked
                            selectByMouse: true
                            width: 50
                            text: '1'
                        }
                        CheckBox{
                            id:shuiwen1
                            text: '水文'
                            onCheckedChanged: {
                                updateDetects()
                            }
                        }
                        Label{
                            text:'海况级数'
                        }
                        TextField{
                            id:seaLevel1
                            enabled: shuiwen1.checked
                            selectByMouse: true
                            text: '3'
                            onEditingFinished: {
                                updateDetects()
                            }
                        }
                        Label{
                            text:'海浪高度(m)'
                        }
                        TextField{
                            enabled: false
                            selectByMouse: true
                            text: parseFloat(seaLevel.text)*.5
                        }
                        Label{
                            text:'海杂波反射强度(dB)'
                        }
                        TextField{
                            enabled: false
                            selectByMouse: true
                            text: -18+parseFloat(seaLevel.text)/2
                        }
                    }
                    Row{
                        CheckBox{
                            id:dianci1
                            text: '电磁'
                            onCheckedChanged: {
                                updateDetects()
                            }
                        }
                        Label{
                            text:'电子干扰(降低探测概率)'
                        }
                        TextField{
                            id:dianziganrao1
                            enabled: dianci1.checked
                            selectByMouse: true
                            text: '0.9'
                            onEditingFinished: {
                                updateDetects()
                            }
                        }
                    }
                }
            }
            Map {
                id: map
                anchors.fill: parent
                plugin:  Plugin {
                    name: "osm"
                }
                center: QtPositioning.coordinate(16, 114)
                zoomLevel: 7
                MouseArea {
                    anchors.fill: parent
                    hoverEnabled:true
                    onPressed: {
                        if(operationState==1){
                            clearDetects()
                            items.push(c.createObject(map))
                            selected=items.length-1
                            map.addMapItemGroup(items[selected])
                            items[selected].index=selected
                            items[selected].coordinate=map.toCoordinate(Qt.point(mouseX, mouseY))
                            items[selected].type='target'
                            items[selected].targetName=comboBoxTarget.model.get(comboBoxTarget.currentIndex).name
                            items[selected].altitude=comboBoxTarget.model.get(comboBoxTarget.currentIndex).altitude
                            items[selected].ref=comboBoxTarget.model.get(comboBoxTarget.currentIndex).ref
                            items[selected].range=comboBoxTarget.model.get(comboBoxTarget.currentIndex).range
                            items[selected].image=comboBoxTarget.model.get(comboBoxTarget.currentIndex).image
                            items[selected].signatureRatio=comboBoxTarget.model.get(comboBoxTarget.currentIndex).signatureRatio
                            items[selected].initiateSignature()
                            createDetects()
                        }
                        else if(operationState==2){
                            clearDetects()
                            items.push(c.createObject(map))
                            selected=items.length-1
                            map.addMapItemGroup(items[selected])
                            items[selected].index=selected
                            items[selected].coordinate=map.toCoordinate(Qt.point(mouseX, mouseY))
                            items[selected].type='sensor'
                            items[selected].sensorName=comboBoxSensor.model.get(comboBoxSensor.currentIndex).name
                            items[selected].altitude=comboBoxSensor.model.get(comboBoxSensor.currentIndex).altitude
                            items[selected].ref=comboBoxSensor.model.get(comboBoxSensor.currentIndex).ref
                            items[selected].range=comboBoxSensor.model.get(comboBoxSensor.currentIndex).range
                            items[selected].image=comboBoxSensor.model.get(comboBoxSensor.currentIndex).image
                            items[selected].signatureRatio=comboBoxSensor.model.get(comboBoxSensor.currentIndex).signatureRatio
                            items[selected].initiateSignature()
                            createDetects()
                        }
                        else if(operationState==3){
                            items[selected].routeline.addCoordinate(map.toCoordinate(Qt.point(mouseX, mouseY)))
                            items[selected].coordinate=items[selected].routeline.path[items[selected].routeline.path.length-1]
                            items[selected].signaturegon.setCurrent()
                            updateDetects()
                        }
                        else if(operationState==4){
                            items[selected].signaturegon.addCoordinate(map.toCoordinate(Qt.point(mouseX, mouseY)))
                        }
                    }
                }
                DropArea{
                    anchors.fill: parent
                    onPositionChanged: {
                        items[drag.source.index].coordinate=map.toCoordinate(Qt.point(drag.x+drag.source.width/2,drag.y+drag.source.height/2),false)
                        items[drag.source.index].signaturegon.setCurrent()
                        updateDetects()
                    }
                }
            }
            Rectangle{
                color: 'white'
                anchors.left: parent.left
                anchors.leftMargin: 8
                anchors.top: parent.top
                anchors.topMargin: 50
                width: 150
                height: 160
                opacity: .8
                TextArea {
                    anchors.fill: parent
                    text: '纬度中心:'+map.center.latitude.toPrecision(6)
                          +'\n经度中心:'+map.center.longitude.toPrecision(6)
                          +'\n地图缩放:'+map.zoomLevel.toPrecision(6)
                          +'\n地图旋转:'+map.bearing.toPrecision(6)
                          +'\n地图倾斜:'+map.tilt
                          +'\n单元数量:'+items.length
                          +'\n标准特征信号:'+standardSignature.toPrecision(6)
                          +'\n标准探测距离:'+(standardRange/1000).toPrecision(6)
                          +'\n当前时间步:'+curStep
                          +'\n总时间步:'+maxStep
                }
            }
            Slider {
                height: 40
                anchors.right: parent.right
                anchors.rightMargin: 8
                anchors.left: parent.left
                anchors.leftMargin: 8
                anchors.bottom: parent.bottom
                anchors.bottomMargin: 8
                value: curStep/(maxStep-1)
                onMoved: {
                    curStep=parseInt((maxStep-1)*value)
                    timer.stop()
                    updateCoordinate()
                    updateDetects()
                }
            }
            Slider {
                width: 40
                anchors.top: parent.top
                anchors.topMargin: 72
                anchors.bottom: parent.bottom
                anchors.bottomMargin: 72
                anchors.right: parent.right
                anchors.rightMargin: 8
                orientation: Qt.Vertical
                from:0
                to:map.maximumTilt
                value: map.tilt
                onMoved: {
                    map.tilt=value
                }
            }
        }
        Page{
            ColumnLayout{
                GroupBox {
                    label: CheckBox {
                        id: qixiang
                        checked: true
                        text: '气象'
                        onCheckedChanged: {
                            updateDetects()
                        }
                    }
                    GridLayout {
                        enabled: qixiang.checked
                        columns: 2
                        CheckBox{
                            id:daqibodao
                            text:'大气波导'
                            onCheckedChanged: {
                                updateDetects()
                            }
                        }
                        Label{
                            opacity: 0
                        }
                        CheckBox{
                            id:cloud
                            text:'云'
                            onCheckedChanged: {
                                updateDetects()
                            }
                        }
                        Label{
                            opacity: 0
                        }
                        CheckBox{
                            id:rain
                            text:'雨(mm/h)'
                            onCheckedChanged: {
                                updateDetects()
                            }
                        }
                        TextField{
                            id:rainVolume
                            text: '0'
                        }
                    }
                }
                GroupBox {
                    label: CheckBox {
                        id: shuiwen
                        checked: true
                        text: '水文'
                        onCheckedChanged: {
                            updateDetects()
                        }
                    }
                    GridLayout{
                        enabled: shuiwen.checked
                        columns: 2
                        Label{
                            text:'海况级数'
                        }
                        TextField{
                            id:seaLevel
                            text: '3'
                            onEditingFinished: {
                                updateDetects()
                            }
                        }
                        Label{
                            text:'海浪高度(m)'
                        }
                        TextField{
                            id:waveHeight
                            enabled: false
                            text: parseFloat(seaLevel.text)*.5
                        }
                        Label{
                            text:'海杂波反射强度(dB)'
                        }
                        TextField{
                            id:seaCluster
                            enabled: false
                            text: -18+parseFloat(seaLevel.text)/2
                        }
                    }
                }
                GroupBox {
                    label: CheckBox {
                        id: dianci
                        checked: true
                        text: '电磁'
                    }
                    GridLayout{
                        enabled: dianci.checked
                        columns: 2
                        Label{
                            text:'电子干扰(降低探测概率)'
                        }
                        TextField{
                            id:dianziganrao
                            text: '0.9'
                            onEditingFinished: {
                                updateDetects()
                            }
                        }
                    }
                }
            }
        }
    }
    Timer{
        id:timer
        interval:100
        repeat: true
        triggeredOnStart:true
        onTriggered: {
            curStep++
            if(curStep>=maxStep){
                stop()
                return
            }
            updateCoordinate()
            updateDetects()
        }
    }
    Component{
        id:d
        MapItemGroup{
            id:dp
            property var fromIndex:0
            property var toIndex:0
            property var from:items[fromIndex].coordinate
            property var to:items[toIndex].coordinate
            property var distance:from.distanceTo(to)
            property var azimuthSensor:from.azimuthTo(to)
            property var azimuthTarget:(to.azimuthTo(from)-items[toIndex].azimuth+360)%360
            property var signature:items[toIndex].signatured[parseInt(azimuthTarget+.5)%360].d
            property var pd: 0
            visible: items[fromIndex].type==='sensor'&&items[toIndex].type==='target'
            function update(){
                if(!visible){
                    return
                }
                signature=items[toIndex].signatured[parseInt(azimuthTarget+.5)%360].d
                detectgon.path=[]
                var fromP=map.fromCoordinate(from)
                var toP=map.fromCoordinate(to)
                var r=Math.sqrt((toP.x-fromP.x)*(toP.x-fromP.x)+(toP.y-fromP.y)*(toP.y-fromP.y))
                var p1=map.toCoordinate(Qt.point(toP.x-(toP.y-fromP.y)/r*25,toP.y+(toP.x-fromP.x)/r*25))
                var p2=map.toCoordinate(Qt.point(toP.x+(toP.y-fromP.y)/r*25,toP.y-(toP.x-fromP.x)/r*25))
                detectgon.addCoordinate(from)
                detectgon.addCoordinate(p1)
                detectgon.addCoordinate(p2)
                pd=Math.pow(.5,items[fromIndex].ref/standardSignature*Math.pow(distance/items[fromIndex].range*standardRange/signature,4))
                if(isStrategyAvailable){
                    if(pd>.5){
                        items[toIndex].jiansuo=true
                    }
                    if(pd>.85){
                        items[toIndex].shijia=true
                    }
                    if(pd>.9){
                        items[toIndex].zhebi=true
                    }
                    if(pd>.95){
                        items[toIndex].ganrao=true
                    }
                    pd=pd<.5?pd:.5+(pd-.5)*.6
                }
                if(qixiang1.checked&&daqibodao1.checked){
                    pd*=.97
                }
                if(qixiang1.checked&&cloud1.checked){
                    pd*=.97
                }
                if(qixiang1.checked&&rain1.checked){
                    pd*=Math.exp(-parseFloat(rainVolume1.text)/10)
                }
                if(shuiwen1.checked){
                    pd*=Math.exp(-parseFloat(seaLevel1.text)/10)
                }
                if(dianci1.checked){
                    pd*=Math.exp(-parseFloat(dianziganrao1.text)/10)
                }
            }
            MapPolygon{
                id:detectgon
                border.width: 0
                color: pd<.05?'green':pd<.7?'yellow':pd<.9?'red':'orange'
                opacity:pd*.8+.1
            }
            MapQuickItem{
                visible: visibleDetects
                coordinate:from.atDistanceAndAzimuth(distance/2,azimuthSensor)
                sourceItem:Text {
                    y:-50
                    text:'距离:'+(distance/1000).toPrecision(6)
                         +'\n目标方位:'+azimuthSensor.toPrecision(6)
                         +'\n被探测方位:'+azimuthTarget.toPrecision(6)
                         +'\n标准探测距离:'+(signature/1000).toPrecision(6)
                         +'\n信号强度:'+(Math.pow(signature/standardRange,4)*standardSignature).toPrecision(6)
                         +'\n探测概率:'+pd.toPrecision(6)
                }
            }
        }
    }
    Component{
        id:c
        MapItemGroup{
            id:mig
            property alias index: rct.index
            property alias coordinate: mqi.coordinate
            property alias routeline: routeline
            property alias signaturegon: signaturegon
            property alias image: image.source
            property var routed: []
            property var signatured: []
            property var rcs: 1000
            property var ir: 1000
            property var noise: 110
            property var altitude: 10000
            property var azimuth: 0
            property var velocity: 800/3.6
            property var range: 100*1000
            property var ref: 1
            property var type: 'target'
            property var targetName: '战斗机'
            property var sensorName: '预警机'
            property var name: type==='target'?targetName:sensorName
            property var signatureRatio: 1
            property var detects: []
            property var jiansuo:false
            property var shijia:false
            property var zhebi:false
            property var ganrao:false
            property var detectedProbability:0
            Component.onCompleted: {
                initiateSignature()
            }
            function initiateSignature(){
                signatured=[]
                for(var a=0;a<360;a++){
                    signatured.push({'a':a,'d':(80000-10000*Math.cos(a*Math.PI/180)-20000*Math.cos(a*Math.PI/180*2)-30000*Math.cos(a*Math.PI/180*4))*signatureRatio})
                }
                signaturegon.setCurrent()
            }
            function setCurrent(number){
                routeline.setCurrent(number)
                signaturegon.setCurrent()
            }
            function updateDetects(){
                detectedProbability=0
                for(var i=0;i<detects.length;i++){
                    detects[i].update()
                    detectedProbability=Math.max(detectedProbability,detects[i].pd*4/5)
                }
                if(isDSAvailable){
                    detectedProbability*=5/4
                }
            }
            MapPolyline {
                id:routeline
                line.width: selected==index?6:3
                opacity: selected==index?.8:0.3
                visible: visibleRouteline
                line.color: type=='target'?'red':'blue'
                function setCurrent(number){
                    if(routed.length>0){
                        coordinate=routed[Math.min(number,routed.length-1)]
                        if(number<5){
                            azimuth=routed[0].azimuthTo(routed[number])
                        }
                        else if(number<routed.length){
                            azimuth=routed[number-5].azimuthTo(routed[number])
                        }
                    }
                    else{
                        azimuth=0
                    }
                }
                function toroute(){
                    routed.length=0
                    var step=velocity*timeInverval
                    var start=0
                    for(var ii=0,t=0;ii<path.length-1;ii++){
                        var d=path[ii].distanceTo(path[ii+1])
                        var a=path[ii].azimuthTo(path[ii+1])
                        while(t<d){
                            routed.push(path[ii].atDistanceAndAzimuth(t,a))
                            t+=step
                        }
                        t-=d
                    }
                }
            }
            MapCircle {
                visible: type=='sensor'&&visibleRange
                center: coordinate
                radius: range
                color: 'blue'
                border.width: 0
                opacity:selected==index?0.2:0.1
            }
            MapPolygon {
                id:signaturegon
                visible: type=='target'&&visibleSignaturegon
                border.width: 0
                color: 'red'
                opacity:selected==index?0.2:0.1
                function tosignature(){
                    var a,d,cda,i,da
                    signatured=[]
                    for(a=0;a<=180;a++){
                        da=360
                        path.forEach(function(item){
                            cda=Math.abs(coordinate.azimuthTo(item)-a)
                            cda=Math.min(360-cda,cda)
                            if(cda<da){
                                da=cda
                                d=coordinate.distanceTo(item)
                            }
                        })
                        signatured.push({'a':a,'d':d})
                    }
                    for(i=181;i<360;i++){
                        signatured[i]={'a':i,'d':signatured[360-i].d}
                    }
                    setCurrent()
                }
                function increase(ratio){
                    for(var i=0;i<360;i++){
                        signatured[i].d*=ratio
                    }
                    setCurrent()
                }
                function setCurrent(){
                    path=[]
                    signatured.forEach(function(item){
                        addCoordinate(coordinate.atDistanceAndAzimuth(item.d,item.a+azimuth))
                    })
                }
            }
            MapQuickItem{
                id:mqi
                anchorPoint.x: rct.width/2
                anchorPoint.y: rct.height/2
                sourceItem:Rectangle{
                    id:rct
                    width: 40
                    height: 40
                    radius:width/2
                    color:'yellow'
                    border.color:'brown'
                    border.width: selected==index?4:0
                    property var index: 0
                    Drag.active: maItemGroup1.drag.active
                    MouseArea{
                        id: maItemGroup1
                        anchors.fill: parent
                        drag.target: parent
                        onPressed: {
                            selected=index
                        }
                        onWheel: {
                            if(wheel.modifiers&Qt.ControlModifier){
                                if(type==='sensor'){
                                    range/=Math.exp(wheel.angleDelta.y/1440)
                                }
                                else
                                {
                                    signaturegon.increase(Math.exp(wheel.angleDelta.y/1440))
                                }
                                window.updateDetects()
                            }
                            if(wheel.modifiers&Qt.ShiftModifier){
                                altitude-=wheel.angleDelta.y*10
                            }
                        }
                    }
                    Rectangle{
                        width: 4
                        height: Math.min(altitude/100,500)
                        x:20-2
                        y:-height+20
                        color: 'green'
                        opacity:selected==index?0.4:0.2
                    }
                    Image {
                        id:image
                        width: 40
                        height: 40
                        x:0
                        y:-Math.min(altitude/100,500)
                    }
                    Column{
                        x:40
                        y:-40
                        ToolButton{
                            autoRepeat: true
                            text: "加速"
                            onClicked: {
                                velocity*=Math.exp(12/1440)
                            }
                        }
                        ToolButton{
                            autoRepeat: true
                            text: "减速"
                            onClicked: {
                                velocity/=Math.exp(12/1440)
                            }
                        }
                    }

//                    TextField{
//                        text:velocity.toPrecision(6)
//                        selectByMouse: true
//                        onEditingFinished: {
//                            velocity=parseFloat(text)
//                        }
//                    }

                    Text{
                        x:20
                        y:20
                        visible: visibleDetail
                        text: '序号:'+index
                              +'\n纬度:'+coordinate.latitude.toPrecision(6)
                              +'\n经度:'+coordinate.longitude.toPrecision(6)
                              +'\n航向:'+azimuth.toPrecision(6)
                              +'\n速度:'+velocity.toPrecision(6)
                              +'\n海拔:'+altitude.toPrecision(6)
                              +'\n探测距离:'+(range/1000).toPrecision(6)
                              +'\n参考特征信号:'+ref.toPrecision(6)
                              +'\n类型:'+typename[type]
                              +'\nRCS:'+rcs.toPrecision(6)
                              +'\n红外辐射强度:'+ir.toPrecision(6)
                              +'\n噪声:'+noise.toPrecision(6)
                        +'\n名称:'+name
                        +'\n信号强度比例:'+signatureRatio
                        +'\n被识别概率:'+(type==='target'?'null':detectedProbability.toPrecision(6))
                    }
                    Rectangle{
                        color: 'red'
                        visible: jiansuo&&type=='target'
                        x:-40
                        y:-20
                        width: 40
                        height: 20
                        Text {
                            anchors.fill: parent
                            text: qsTr("减缩")
                        }
                    }
                    Rectangle{
                        color: 'lightgreen'
                        visible: shijia&&type=='target'
                        x:-40
                        y:-40
                        width: 40
                        height: 20
                        Text {
                            anchors.fill: parent
                            text: qsTr("示假")
                        }
                    }
                    Rectangle{
                        color: 'cyan'
                        visible: zhebi&&type=='target'
                        x:-40
                        y:-60
                        width: 40
                        height: 20
                        Text {
                            anchors.fill: parent
                            text: qsTr("遮蔽")
                        }
                    }
                    Rectangle{
                        color: 'yellow'
                        visible: ganrao&&type=='target'
                        x:-40
                        y:-80
                        width: 40
                        height: 20
                        Text {
                            anchors.fill: parent
                            text: qsTr("干扰")
                        }
                    }
                }
            }
        }
    }
}
